package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.dto.TradeClientDto;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.domain.vo.CourseStateVo;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * <p>
 * 学生课表 控制器
 * </p>
 *
 * @author xjs
 */
@Api(tags = "LearningLesson管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/lessons")
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;


    /**
     * 我的课表分页查询
     * */
    @ApiOperation("我的课表分页查询")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> page(PageQuery query){
        return learningLessonService.pageQuery(query);
    }

    /**
     * 查询正在学习的课程
     * */
    @ApiOperation("查询正在学习的课程")
    @GetMapping("/now")
    public LearningLessonVO now(){
        return learningLessonService.now();
    }

    @DeleteMapping("/lessons/trade/delete")
    @ApiOperation("退款订单删除课程")
    public void deleteRefund(TradeClientDto dto){
        learningLessonService.deleteRefund(dto);
    }

    @ApiOperation(value = "用户删除课程")
    @DeleteMapping("user/delete")
    public void deleteCourseByCourseId(Long courseId){
        learningLessonService.deleteCourseByCourseId(courseId);
    }

    @ApiOperation(value = "检查课程是否有效")
    @GetMapping("/{courseId}/valid")
    public Long isLessonValid(@PathVariable("courseId") Long courseId){
        return learningLessonService.findCourseState(courseId);
    }

    @ApiOperation(value = "查询用户课表中指定课程状态")
    @GetMapping("/{courseId}")
    public CourseStateVo checkCourseState(@PathVariable("courseId") Long courseId){
        return   learningLessonService.checkCourseState(courseId);
    }

    @ApiOperation(value = "统计课程的学习人数")
    @GetMapping("/{courseId}/count")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return  learningLessonService.countLearningLessonByCourse(courseId);
    }
    /**
     * 创建学习计划
     *
     */
    @PostMapping("/plans")
    public void plans(@RequestBody LearningPlanDTO dto){
        learningLessonService.plan(dto);
    }


    @GetMapping("/plans")
    public LearningPlanPageVO getPlans(PageQuery query){
        return learningLessonService.getPlans(query);
    }

}